package com.changgou.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.pojo.Sku;
import com.changgou.service.SkuService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品sku信息控制层
 *
 * @author gaofeng
 * @date 2025/4/20 10:51
 */
@Api(value = "SkuController")
@RestController
@RequestMapping("/sku")
@CrossOrigin
public class SkuController {
    @Resource
    private SkuService skuService;

    /**
     * Sku分页条件搜索实现
     *
     * @param sku  查询条件
     * @param page 当前页
     * @param size 每页显示条数
     * @return sku分页信息
     */
    @ApiOperation(value = "Sku条件分页查询", notes = "分页条件查询Sku方法详情", tags = {"SkuController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}")
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "Sku对象", value = "传入JSON数据") Sku sku, @PathVariable int page, @PathVariable int size) {
        return new Result<>(true, StatusCode.OK, "查询成功", skuService.findPage(sku, page, size));
    }

    /**
     * Sku分页搜索实现
     *
     * @param page 当前页
     * @param size 每页显示多少条
     * @return sku分页信息
     */
    @ApiOperation(value = "Sku分页查询", notes = "分页查询Sku方法详情", tags = {"SkuController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}")
    public Result<PageInfo> findPage(@PathVariable int page, @PathVariable int size) {
        return new Result<>(true, StatusCode.OK, "查询成功", skuService.findPage(page, size));
    }

    /**
     * 多条件搜索品牌数据
     *
     * @param sku 查询条件
     * @return sku数据列表
     */
    @ApiOperation(value = "Sku条件查询", notes = "条件查询Sku方法详情", tags = {"SkuController"})
    @PostMapping(value = "/search")
    public Result<List<Sku>> findList(@RequestBody(required = false) @ApiParam(name = "Sku对象", value = "传入JSON数据") Sku sku) {
        return new Result<>(true, StatusCode.OK, "查询成功", skuService.findList(sku));
    }

    /**
     * 根据ID删除品牌数据
     *
     * @param id 主键
     * @return 响应结果
     */
    @ApiOperation(value = "Sku根据ID删除", notes = "根据ID删除Sku方法详情", tags = {"SkuController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Long")
    @DeleteMapping(value = "/delete/{id}")
    public Result delete(@PathVariable Long id) {
        skuService.delete(id);
        return new Result<>(true, StatusCode.OK, "删除成功");
    }

    /**
     * 修改Sku数据
     *
     * @param sku sku信息
     * @param id  主键
     * @return 响应结果
     */
    @ApiOperation(value = "Sku根据ID修改", notes = "根据ID修改Sku方法详情", tags = {"SkuController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Long")
    @PutMapping(value = "/update/{id}")
    public Result update(@RequestBody @ApiParam(name = "Sku对象", value = "传入JSON数据") Sku sku, @PathVariable Long id) {
        sku.setId(id);
        skuService.update(sku);
        return new Result<>(true, StatusCode.OK, "修改成功");
    }

    /**
     * 新增Sku数据
     *
     * @param sku sku信息
     * @return 响应结果
     */
    @ApiOperation(value = "Sku添加", notes = "添加Sku方法详情", tags = {"SkuController"})
    @PostMapping(value = "/add")
    public Result add(@RequestBody @ApiParam(name = "Sku对象", value = "传入JSON数据", required = true) Sku sku) {
        skuService.add(sku);
        return new Result<>(true, StatusCode.OK, "添加成功");
    }

    /**
     * 根据ID查询Sku数据
     *
     * @param id 主键
     * @return Sku数据
     */
    @ApiOperation(value = "Sku根据ID查询", notes = "根据ID查询Sku方法详情", tags = {"SkuController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Long")
    @GetMapping("/findById/{id}")
    public Result<Sku> findById(@PathVariable Long id) {
        return new Result<>(true, StatusCode.OK, "查询成功", skuService.findById(id));
    }

    /**
     * 查询Sku全部数据
     *
     * @return sku数据列表
     */
    @ApiOperation(value = "查询所有Sku", notes = "查询所Sku有方法详情", tags = {"SkuController"})
    @GetMapping(value = "/findAll")
    public Result<List<Sku>> findAll() {
        return new Result<>(true, StatusCode.OK, "查询成功", skuService.findAll());
    }
}
